#include <QString>
#include <QtTest>
#include <QtGlobal>
//学习使用qtTest

#include "report.h"

class TestTest : public QObject
{
    Q_OBJECT

public:
    TestTest();
    ~TestTest();

private Q_SLOTS:
    void testCase1();

    void testMargin_data();

    void testMargin();


private:
    YReport::Report *report;
};

TestTest::TestTest()
{
    report =  new YReport::Report(this);
}

TestTest::~TestTest()
{
}

void TestTest::testCase1()
{
    QVERIFY2(true, "Failure");
}

void TestTest::testMargin_data()
{
    QTest::addColumn<qreal> ("setData");
    QTest::addColumn<qreal> ("getData");

    QTest::newRow("positive num") << (qreal)5.5f << (qreal)5.5f;
    QTest::newRow("minus num") << (qreal)-3.4f << (qreal)0.0f;
    QTest::newRow("zero") << (qreal)0.0f << (qreal)0.0f;
}

void TestTest::testMargin()
{
    QFETCH(qreal, setData);
    QFETCH(qreal, getData);

    //下面QCOMPARE和QVERIFY效果一样
    report->setRightMargin(setData);
    QCOMPARE(report->rightMargin(), getData);
    QVERIFY(qFuzzyCompare(report->rightMargin(), getData));


    report->setLeftMargin(setData);
    QCOMPARE(report->leftMargin(), getData);

    report->setTopMargin(setData);
    QCOMPARE(report->topMargin(), getData);

    report->setBottomMargin(setData);
    QCOMPARE(report->bottomMargin(), getData);

    report->setMargins(setData);
    QCOMPARE(report->rightMargin(), getData);
    QCOMPARE(report->leftMargin(), getData);
    QCOMPARE(report->topMargin(), getData);
    QCOMPARE(report->bottomMargin(), getData);
}



/*!
    使用QTEST_APPLESS_MAIN( TestClass)时提示
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    QFATAL : TestTest::testRightMargin() QPrinter: Must construct a QCoreApplication before a QPrinter
    换成如下宏定义
  */
QTEST_MAIN(TestTest)

#include "tst_testtest.moc"
